<template>
	<view>
		<top-tabbar :tabTitle="i18n.StarList" backColor="#5B2177" @backClick="backClick"></top-tabbar>
		<!-- 明星列表 -->
		<view class="main">
			<view class="celeb-list" v-for="(item,index) in celebList" :key="item.id">
				<view class="img-box">
					<image class="img" mode="aspectFill" src="@/static/home/celebrity.jpeg" v-if="!item.furl"></image>
					<image :src="item.furl" class="img" v-else></image>
				</view>
				<view class="first">{{item.nick}}</view>
				<view class="fans">{{item.fansCount}} {{ i18n.fans }}</view>
				<view v-if="item.id !== userData.id">
					<view class="followed" v-if="item.isFollow==1"  @click="cancelFollow(item.id)" style="background: #999999;">{{ i18n.Concerned}}</view>
					<view class="followed" v-else @click="attention(item.account,item.id)">{{ i18n.follow }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import topTabbar from '@/components/top-tabbar.vue'
	import { $POST, $GET } from '@/network/api.js'
	export default {
		components: { topTabbar },
		computed: {
			i18n () {  
				return this.$t('home')  
			}  
		 },
		data() {
			return {
				userData: uni.getStorageSync('user_key'), // 获取个人信息
				isAttenFrom: { // 取消关注的参数
					followId: '', // 被关注者用户id
					fansId: '', // 登录人id
				},
				attentionFrom: { // 关注参数
					fansAccount: '', // 登录账号
					fansId: '', // 登录人id
					followAccount: '', // 被关注者用户登录账号
					followId: '', // 被关注者用户id
					followTime: new Date().getTime() // 关注时间
				},
				celebrityForm: { // 明星排行参数
					pageNum: 1,
					pageSize: 10,
					userId: ''
				},
				celebList: [] // 明星数据
			}
		},
		onLoad() {
			this.celebrityForm.userId = this.userData.id // 登录人id赋值
			this.celebrity() // 明星排行
		},
		methods:{
			// 关注
			async attention(account,id) {
				this.attentionFrom.fansAccount = this.userData.account // 登录人账号赋值
				this.attentionFrom.fansId = this.userData.id // 登录人id赋值
				this.attentionFrom.followAccount = account // 被关注账号赋值
				this.attentionFrom.followId = id // 被关注id赋值
				 const res = await $POST("/boke-user/user/follow",this.attentionFrom)
				 if(res.code === "0000000") {
					 this.celebrity()
				 }
				},
			// 取消关注
			cancelFollow(id) {
				this.isAttenFrom.followId = id  // 被关注id赋值
				this.isAttenFrom.fansId = this.userData.id // 登录人id赋值
				$POST("/boke-user/user/cancelFollow",this.isAttenFrom).then(res => {
					if(res.code === "0000000") {
						this.celebrity()
					}
				})
			},
			// 获取明星排行
			celebrity() {
				$POST( '/boke-item/channel/getStarZoneRank',this.celebrityForm).then(res => {
					this.celebList = res.data
				})
			},
			// 返回上一页
			backClick() {
				uni.switchTab({
					url: "/pages/home/index"
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		padding: 38rpx 25rpx 0 25rpx;
		display: flex;
		flex-wrap: wrap;
		.celeb-list:nth-child(3n) {
		 margin-right: 0 !important;
		}
		.celeb-list{
			width: 220rpx;
			// height: 321rpx;
			padding: 30rpx 0;
			background: #FFFFFF;
			// border: 1rpx solid rgba(0, 0, 0, 0.14);
			box-shadow: 0px 4rpx 7rpx 0px rgba(0, 0, 0, 0.14);
			border-radius: 5rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin: 0 20rpx 20rpx 0;
			.img-box{
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				.img{
					width: 100%;
					height: 100%; 
					border-radius: 50%;
				}
			}
			.first{
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				margin: 20rpx 0 17rpx 0;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1;
				overflow: hidden;
			}
			.fans{
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
			}
			.followed{
				display: inline-block;
				padding: 8rpx 30rpx;
				background: linear-gradient(90deg, #B83DF1, #852CAE);
				border-radius: 25rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				margin-top: 20rpx;
			}
			.gray{
				background: #999999 !important;
			}
		}
	}
</style>
